Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a default home page #16

Merged
merged 7 commits into from
Sep 25, 2018
Merged

feat: add a default home page #16

merged 7 commits into from
Sep 25, 2018

Conversation

raymondfeng
Copy link
Contributor

Add a default home page for the app. We'll use it as a template for loopbackio/loopback-next#1745.

We need to fix @loopback/rest so that it respects the correct content-type from responses. At the moment, the home page will render raw html as the media type is plain/text for string response from the controller method.

@virkt25
Copy link
Contributor

virkt25 commented Sep 24, 2018

I made the following changes to get the page to render :D

image

Render:

image

Looks good overall -- have some concerns with the resources we're loading -- will leave a comment.

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip out on loading the full bootstrap.min.css and the accompanying js file? We're using about 2 styles from this entire file. I'd rather we copy the style in-lined for a faster render. No JS is needed. (Currently this + JS is loading 63.1 KB while the page payload is only 1.7 KB).

An alternative IIRC is that BootStrap also provides just the grid CSS -- which is lighter and includes the CSS for container class.

</footer>
<!-- Bootstrap core JavaScript -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing on this page needs the JS ... no BootStrap widgets are used.

<div class="container">
<h1>${this.name}@${this.version}</h1>
<ul>
<li><a href="/openapi.json">OpenAPI spec: /openapi.json</a></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we style the list to be bigger. Plus can OpenAPI spec: not be part of the link. Bolded. Would be a better style imo.

Same applies for the bullet below.

</div>
<footer>
<div class="container">
<p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's center this text on the page.

@raymondfeng
Copy link
Contributor Author

@virkt25 You worked around the issue by manipulating Express response directly. In this case, we should introduce a special return value such as ByPassResponse so that our writer won't try to send 204.

Feel free to improve the UI. I'm a beginner there :-).

@virkt25
Copy link
Contributor

virkt25 commented Sep 24, 2018

You worked around the issue by manipulating Express response directly. In this case, we should introduce a special return value such as ByPassResponse so that our writer won't try to send 204.

I think a simpler fix can even be just to check if Content-Type header has been set in the writer ... and if so we don't overwrite it -- and then we can rely on the response.end in the write.

And of course in the long term it should request the responses decorator + the expected content type header.

Feel free to improve the UI. I'm a beginner there :-).

I'll push some changes to the PR in a bit :)

raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
@raymondfeng raymondfeng force-pushed the home-page branch 2 times, most recently from 4667561 to 2258e98 Compare September 24, 2018 18:28
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 24, 2018
@raymondfeng
Copy link
Contributor Author

raymondfeng commented Sep 24, 2018

Please note that the CI failure is not related to this change. It will be fixed as part of #14.

@raymondfeng raymondfeng force-pushed the home-page branch 2 times, most recently from f1cc2bb to 23da6cb Compare September 24, 2018 22:34
@virkt25
Copy link
Contributor

virkt25 commented Sep 24, 2018

Here's a screenshot for the UI -- no external CSS / JS. Minor variances with some alternatives below. I personally vote for Alternative 1 (I tried it after pushing my changes otherwise I would've included that in the PR). Anyone else have any preferences? cc: @raymondfeng @bajtos @strongloop/sq-lb-apex

Current:
image

Alternative 1:
image

Alternative 2:
image

Alternative 3:
image

raymondfeng added a commit to loopbackio/loopback-next that referenced this pull request Sep 25, 2018
@bajtos
Copy link
Member

bajtos commented Sep 25, 2018

I vote for Alternative 1.

Perhaps instead of using name@version format, can we move the version number to line 2, to make it more explicit what is version and what is the app name?

A mock-up:

@loopback/example-shopping
version 1.0.0

<body>
<h1 style="text-align: center">${name}@${version}</h1>
<h3>OpenAPI spec: <a href="/openapi.json">/openapi.json</a></h4>
<h3>API Explorer: <a href="/explorer">/explorer</a></h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, applications can customize the URL of both OpenAPI spec and Explorer. See loopbackio/loopback-next#1637, Customize How OpenAPI Spec is Served and Configure the API Explorer.

IMOL, the home page should respect these settings. Eventually :) I am fine to keep the current static version as the first baby step.

description: string;
render: TemplateExecutor;

constructor(@inject(RestBindings.Http.RESPONSE) private res: Response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use response instead of res please?

import {inject} from '@loopback/context';
import {RestBindings, Response} from '@loopback/rest';

const pkg = require('../../../package.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the perspective of clean design and Dependency Injection pattern, I think controller should not depend package.json directly, but get it injected from app context. Then the application should bind the content of package.json (maybe a subset of properties only?) in its constructor.

Not a big deal for this particular pull request, but I think we should think more about the design patterns when we start working on adding HomePageController to our project template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm thinking about the same direction while I work on this implementation.

@raymondfeng raymondfeng force-pushed the home-page branch 2 times, most recently from 7cfc221 to 226347d Compare September 25, 2018 15:10
@raymondfeng raymondfeng force-pushed the home-page branch 2 times, most recently from 366433c to 5334669 Compare September 25, 2018 18:09
Signed-off-by: Raymond Feng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants